#ifndef CPP_PROJECT_CARD_H
#define CPP_PROJECT_CARD_H

#include <string>
#include "game_exception.h"
#include "constant.h"
#include <iostream>
#include <vector>
using namespace std;


class Card {
private:
    unsigned int *point; // \0
    CardColor color;   //卡牌对应的颜色（不同产业）
    bool isLandmarkBuilding = false; //是否是地标建筑
    bool isBaseBuilding = false; //是否是起始基础建筑
    unsigned int type;  //type=0~20  总共有21种牌
    unsigned int no;  //no=0~107  总共有108张卡牌
    unsigned int cost; //每个建筑的价格
    string name;    //每个建筑的名称
public:
    Card(unsigned int t, unsigned int n);
    const unsigned int getType() const {return type;}
    const unsigned int getNo() const {return no;}
    const bool getIsLandmarkBuilding() const {return isLandmarkBuilding;}
    const bool getIsBaseBuilding() const {return isBaseBuilding;}
    const bool isTriggeringTheCard(unsigned int p) const;
    const CardColor getColor() const {return color;}
    const unsigned int getCost() const {return cost;}
    const string getName() const {return name;}
    string toString();
    ~Card() {delete[] point;}
};

inline ostream& operator<<(ostream &o, const Card& card) {
    o << card.getName() << "(" << card.getCost() << ")";
//    ost << card.toString();
    return o;
}

class CardsTab {
private:
    vector<Card*> cards;
    const unsigned int totalNumOfCards = 108;
    static CardsTab* instance;
    CardsTab();
public:
    ~CardsTab();
    static CardsTab& getInstance() {
        if (instance == nullptr) {
            instance = new CardsTab();
        }
        return *instance;
    }
    static void deleteInstance() {
        delete instance;
    }
    const Card & getCard(size_t i) const {  //提供获取卡牌的接口
        if(i>108) throw GameException("Wrong parameter: type of card not exist.");
        return *cards[i];
    }

};

inline bool operator==(const Card &c1, const Card &c2) {
    return c1.getNo() == c2.getNo();
}

#endif //CPP_PROJECT_CARD_H
